﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RearLivestock.Common.Domains.wbx;
using RearLivestock.Common.Domains.zjy;
using RearLivestock.Common.Dtos;
using RearLivestock.RBAC.Api.Application.zjyApplication.Commands.Permissionses;
using System.Security.Cryptography;

namespace RearLivestock.RBAC.Api.Controllers.zjy
{
    /// <summary>
    /// 权限控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class PermissionsController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PermissionsController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("AddPermissions")]
        public async Task<Result> AddPermissions(CreatePermissionsCommand cmd)
        {
            var result = await _mediator.Send(cmd);
            return result;
        }

        /// <summary>
        /// 添加角色权限
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("AddRolePermissions")]
        public async Task<Result> AddRolePermissions(CreateRolePermissionsCommand cmd)
        {
            var result = await _mediator.Send(cmd);
            return result;
        }

        /// <summary>
        /// 获取权限功能
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("GetPermissions")]
        public async Task<Result<List<Permissions>>> GetPermissions(SearchPermissionsCommand cmd)
        {
            var result = await _mediator.Send(cmd);
            return result;
        }

        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("GetAllRole")]
        public async Task<Result<List<Roles>>> GetAllRole(SearchALLRoleCommand cmd)
        {
            var result = await _mediator.Send(cmd);
            return result;
        }

        /// <summary>
        /// 显示角色权限列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("GetRolePermissions")]
        public async Task<Result<PageResultDto<RolePermissionsDto>>> GetRolePermissions(SearchRolePermissionsCommand cmd)
        {
            var result = await _mediator.Send(cmd);
            return result;
        }

        /// <summary>
        /// 删除角色权限
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut("DeleteRolePermissions")]
        public async Task<Result> DeleteRolePermissions(DeletedRolePermissionCommand cmd)
        {
            var result = await _mediator.Send(cmd);
            return result;
        }
    }
}
